package leetcode;

import java.util.Arrays;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-23 17:45
 **/
public class LeetCode5989 {

    public int countElements(int[] nums) {
        int n = nums.length;
        if (n == 1) {
            return 0;
        }
        Arrays.sort(nums);
        int l = 0;
        int r = n - 1;
        while (l + 1 < n) {
            if (nums[l] == nums[l + 1]) {
                ++l;
            } else {
                break;
            }
        }

        while (r - 1 >= 0) {
            if (nums[r] == nums[r - 1]) {
                --r;
            } else {
                break;
            }
        }
        return r > l ? r - l - 1 : 0;
    }

}
